package cn.tomas.rabbit.topic.listener;

import cn.tomas.rabbit.dto.UserDTO;
import com.alibaba.fastjson.JSONObject;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author Mr.Still
 * @version 1.0.0
 * @date 2021-11-11 10:42
 **/
@Component
public class TopicListener {

    @RabbitListener(queues = "topic.error.queue")
    public void errorListener(String msg) throws Exception {
        UserDTO o = JSONObject.parseObject(msg, UserDTO.class);
        System.out.println(JSONObject.toJSONString(o) + "------ topic.error.queue ----" + new Date().toString());
    }

    @RabbitListener(queues = "topic.info.queue")
    public void infoListener(String msg) throws Exception {
        UserDTO o = JSONObject.parseObject(msg, UserDTO.class);
        System.out.println(JSONObject.toJSONString(o) + "------ topic.info.queue ----" + new Date().toString());
    }

    @RabbitListener(queues = "topic.warning.queue")
    public void warningListener(String msg) throws Exception {
        UserDTO o = JSONObject.parseObject(msg, UserDTO.class);
        System.out.println(JSONObject.toJSONString(o) + "------ topic.warning.queue ----" + new Date().toString());
    }

 /*   @RabbitListener(queues = "queue.simple")
    public void readMessage(Message message, Channel channel) throws IOException {
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        System.out.println("消费信息："+new String(message.getBody()));
    }*/
}
